﻿<?php include("conn.php");
mysql_query('SET NAMES UTF8'); 

	  

class MyPrizeBean{
	public $dizhi;
	function __construct($dizhi){
		$this->dizhi      = $dizhi;
	}
}

// 需传参数 
$ordersid = $_REQUEST['ordersid'];
// 需传参数 end

// 状态
$state1 = 1;
// 状态 end

$ordersids = explode(',', $ordersid);
$len = count($ordersids);

for ($i=0; $i < $len; $i++) {
	// 查找订单信息 
	$query = mysql_query("select type,shopid,userid from goodsorders where ordersid=".$ordersids[$i]);
	$orders = mysql_fetch_assoc($query);
	$type = $orders['type'];
	$shopid = $orders['shopid'];
	$userid = $orders['userid'];
	// 查找订单信息 end

	// 生成商家返券
	$query = mysql_query("select goodsid,price,number from car where ordersid=".$ordersids[$i]);
	$can_fanquan_total = 0;
	while ($row = mysql_fetch_assoc($query)) {
		// 判断该商品是否支付返券
		$sql = mysql_query("select can_fanquan from goods where goodsid=".$row['goodsid']);
		$goods = mysql_fetch_assoc($sql);
		$can_fanquan = $goods['can_fanquan'];
		if ($can_fanquan == 1) {
			$can_fanquan_total+= $row['price']*$row['number'];
		}
		// 判断该商品是否支付返券 end
	}

	// 查找返券
	$query = mysql_query("select htfanquan,kgfanquan from shop where shopid=".$shopid);
	$shop = mysql_fetch_assoc($query);
	$shophtfanquan = $shop['htfanquan'];
	$shopkgfanquan = $shop['kgfanquan'];
	// 查找商家返券 end

	// 查找平台返券 
	$query = mysql_query("select htfanquan,kgfanquan from xitong where id=1");
	$xitong = mysql_fetch_assoc($query);
	$htfanquan = $xitong['htfanquan'];
	$kgfanquan = $xitong['kgfanquan'];
	// 查找平台返券 end
	if ($type == 0) {
		$shopfanquan = $can_fanquan_total*$shophtfanquan;
		$fanquan = $can_fanquan_total*$htfanquan;
	}elseif ($type == 1) {
		$shopfanquan = $can_fanquan_total*$shopkgfanquan;
		$fanquan = $can_fanquan_total*$kgfanquan;
	}
	// 生成商家返券 
	if ($shopfanquan > 0) {
		$query = mysql_query("INSERT myfanquan (userid,shopid,price,type) VALUES (".$userid.",".$shopid.",".$shopfanquan.",".$type.")");
	}
	// 生成商家返券 end

	// 生成平台返券 
	if ($fanquan > 0) {
		$query = mysql_query("INSERT myfanquan (userid,price,type) VALUES (".$userid.",".$fanquan.",".$type.")");
	}
	// 生成平台返券 end

	// 生成返券 end

	$query = mysql_query("update goodsorders set state='".$state1."' where ordersid='".$ordersids[$i]."'");
	// 调用信息推送接口
	// $url = "http://120.24.0.10/xzpf/api/jpush/jpush.php?state=".$states."&ordersid=".$ordersid[$i];
	// file_get_contents($url);
	// 调用信息推送接口 end
}
$mydizhi="12";

$prize[] = new MyPrizeBean($mydizhi);
		


echo json_encode($prize);


?>